﻿using MinesweeperAutoScanDemo.Enums;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using NotifyPropertyBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MinesweeperAutoScanDemo.Model
{
    public class EarthModel : ObservableObject
    {
        public EarthModel()
        {

        }
        public EarthModel(int row, int column, string imagePath)
        {
            Row = row;
            Column = column;
            ImagePath = imagePath;
        }
        public EarthModel(ImageChip chip)
        {
            ImageChip = chip;
            Row = chip.Row;
            Column = chip.Column;
            ImagePath = chip.DeBUGPath;
        }
        public int Row { get; set; }
        public int Column { get; set; }

        private EathStatus _Status;
        [JsonConverter(typeof(StringEnumConverter))]
        public EathStatus Status { get => _Status; set => Set(ref _Status, value); }


        private int _BomboNumber;
        public int BomboNumber { get => _BomboNumber; set => Set(ref _BomboNumber, value); }

        private string _ImagePath;
        public string ImagePath { get => _ImagePath; set => Set(ref _ImagePath, value); }

        [JsonIgnore]
        public ImageChip ImageChip { get; set; }

     


        public void DoubleClick(System.Drawing.Rectangle CutRect)
        {
            var x = CutRect.X + this.ImageChip.Rect.X + this.ImageChip.Rect.Width / 2;
            var y = CutRect.Y + this.ImageChip.Rect.Y + this.ImageChip.Rect.Height / 2;

            AutoIt.AutoItX.MouseMove(x, y);
            AutoIt.AutoItX.MouseClick("LEFT", x, y, 2);
        }

        public void MarkBomboClick(System.Drawing.Rectangle CutRect)
        {
            var x = CutRect.X + this.ImageChip.Rect.X + this.ImageChip.Rect.Width / 2;
            var y = CutRect.Y + this.ImageChip.Rect.Y + this.ImageChip.Rect.Height / 2;

            AutoIt.AutoItX.MouseMove(x, y);
            AutoIt.AutoItX.MouseClick("RIGHT", x, y, 1);
        }

        public override bool Equals(object obj)
        {
            var other = obj as EarthModel;
            if (other == null) return false;
            return this.Row == other.Row && this.Column == other.Column;
        }

        public override int GetHashCode()
        {
            return $"{this.Row}_{this.Column}".GetHashCode();
        }
    }
}
